// pages/order/createOrder/createOrderNext.js

const app = getApp();

let api = require('../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      orderId: options.id,
      lastData: JSON.parse(options.data)
    })

  },
  payment: function(e) {
    var that = this;
    var token = wx.getStorageSync('TOKEN');
    var orderId = parseInt(that.data.orderId);
    var param = {
      "id": orderId,
      "state": 8
    }
    api._put('/omc/order/action', param, token).then(res => {
      if (res.code == 200) {
        +
        wx.requestSubscribeMessage({
          tmplIds: ['3_vNmvSBoT91eWrfzY3UvqFNpYjpYyuPKO8LmIlYwHw', 'ILWa29t_Y6iDlV-HDdrxvi5-lFtTgaQKBOi-LNucu20'], // 此处可填写多个模板 ID，但低版本微信不兼容只能授权一个
          success(res) {
           // console.log('已授权接收订阅消息')
          }
        })
        wx.switchTab({
          url: '../../index/index',
          success: function () {
            var page = getCurrentPages().pop();
            if (page == undefined || page == null) {
              return
            }
            page.onLoad();
          }
        })
      } else if (res.code == 30000011) {
        wx.showModal({
          title: '提示',
          content: res.message,
          cancelText: '取消',
          confirmText: '确定',
          success(res) {
            if (res.cancel) {
              // 用户点击了取消属性的按钮
            } else if (res.confirm) {
              // 用户点击了确定属性的按钮
              wx.switchTab({
                url: '../../index/index',
              });
            }
          }
        });
     
      } else {
        wx.showToast({
          title: '网络忙请重试',
          icon: 'none',
        })
      }
    })
   
  }
})